package com.azkj.album.network.service;


import android.graphics.Bitmap;

import com.azkj.album.BuildConfig;
import com.azkj.album.dto.BannerBean;
import com.azkj.album.dto.HasNickName;
import com.azkj.album.dto.LoginBean;
import com.azkj.album.dto.UploadBean;
import com.azkj.album.dto.WxBean;
import com.azkj.album.network.NetworkMaster;
import com.azkj.album.network.callback.ServiceCallback;
import com.azkj.album.network.callback.UploadCallback;
import com.azkj.album.network.networkframe.api.CommonApi;
import com.azkj.album.network.networkframe.bean.BaseResp;
import com.azkj.album.network.networkframe.bean.BitmapRequestBody;
import com.azkj.album.network.networkframe.bean.FileRequestBody;
import com.azkj.album.network.networkframe.net.HttpsUtil;
import com.azkj.album.network.networkframe.net.rx.RxService;
import com.azkj.album.network.networkframe.net.rx.RxUtil;
import com.vachel.editor.util.BitmapManager;

import java.io.File;
import java.util.List;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class CommonService extends BaseService {
    //用户
    public String USER_SERVER = NetworkMaster.getInstance().getHostUrl() + "/api/user/";
    public String API_SERVER = NetworkMaster.getInstance().getHostUrl() + "/api/";
    public String SMS_SERVER = NetworkMaster.getInstance().getHostUrl() + "/api/sms/";
    public String HOME_SERVER = NetworkMaster.getInstance().getHostUrl() + "/api/index/";
    public String COMPANY_SERVER = NetworkMaster.getInstance().getHostUrl() + "/api/company/";
    public String ORDER_SERVER = NetworkMaster.getInstance().getHostUrl() + "/api/order/";
    public String COLLECT_SERVER = NetworkMaster.getInstance().getHostUrl() + "/api/collect/";
    public String ORDER_SEARCH_SERVER = NetworkMaster.getInstance().getHostUrl() + "/api/order_search/";
    public String COMMON_SERVER = NetworkMaster.getInstance().getHostUrl() + "/api/common/";
    public String PRICE_SERVER = NetworkMaster.getInstance().getHostUrl() + "/api/product_price/";
    public String SALE_SEARCH_SERVER = NetworkMaster.getInstance().getHostUrl() + "/api/sale_search/";
    public String USER_BIND_SERVER = NetworkMaster.getInstance().getHostUrl() + "/api/user_bind/";
    public String CATEGORY = NetworkMaster.getInstance().getHostUrl() + "/api/album/";
    public String CATEGORY_SYS = NetworkMaster.getInstance().getHostUrl() + "/api/album_map/";
    //获取VIP信息
    public String VIP_INFO = NetworkMaster.getInstance().getHostUrl() + "/api/user/vipInfo/";
    public String MEMBERSHIP_RULES = NetworkMaster.getInstance().getHostUrl() + "/api/index/MembershipRules/";
    public String VIP_CARD = NetworkMaster.getInstance().getHostUrl() + "/api/pay/vipcard/";
    public String HISTORY = NetworkMaster.getInstance().getHostUrl() + "/api/pay/history/";
    public String PHOTO_CLASS = NetworkMaster.getInstance().getHostUrl() + "/api/album/category/";
    public String UPLOAD_FILE = NetworkMaster.getInstance().getHostUrl() + "/api/common/upload/";
    public String POST_SAVE = NetworkMaster.getInstance().getHostUrl() + "/api/album/save/";
    public String BACK_CATEGORY = NetworkMaster.getInstance().getHostUrl() + "/api/album_background/category/";
    public String BACK_LIST = NetworkMaster.getInstance().getHostUrl() + "/api/album_background/list/";
    public String VIP_PAY = NetworkMaster.getInstance().getHostUrl() + "/api/pay/";
    public String INTRO = NetworkMaster.getInstance().getHostUrl() + "/api/album_history/intro/";
    public String REEMARK = NetworkMaster.getInstance().getHostUrl() + "/api/album_history/remark/";
    public String CAN_ADDORDER = NetworkMaster.getInstance().getHostUrl() + "/api/album/canAddOrder/";
    public String DELETE_INTRO = NetworkMaster.getInstance().getHostUrl() + "/api/album_history/deleteIntro/";
    public String DELETE_REMARK = NetworkMaster.getInstance().getHostUrl() + "/api/album_history/deleteRemark/";
    //增加使用次数
    public String ADD_USECOUNT = NetworkMaster.getInstance().getHostUrl() + "/api/album_map/addUseCount/";

    public String WX_SERVER = "https://api.weixin.qq.com/sns/";


    private static CommonService mInstance;

    public static CommonService getInstance() {
        if (mInstance == null) {
            mInstance = new CommonService();

        }
        return mInstance;
    }


    public void login(Map<String, Object> body, ServiceCallback callback) {
        RxService.createBasicApi(CommonApi.class, mInstance.USER_SERVER).login(body).compose(RxUtil.<BaseResp<LoginBean>>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void loginSms(Map<String, Object> body, ServiceCallback callback) {
        RxService.createBasicApi(CommonApi.class, mInstance.USER_SERVER).loginSms(body).compose(RxUtil.<BaseResp<LoginBean>>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void hasNickName(String name, ServiceCallback callback) {
        RxService.createBasicApi(CommonApi.class, mInstance.USER_SERVER).hasNickName(name).compose(RxUtil.<BaseResp<HasNickName>>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void changenickName(String token, String name, ServiceCallback callback) {
        RxService.createBasicApi(CommonApi.class, mInstance.USER_SERVER).changenickName(token, name).compose(RxUtil.<BaseResp<Object>>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }


    public void loginVisitor(Map<String, Object> body, ServiceCallback callback) {
        RxService.createBasicApi(CommonApi.class, mInstance.USER_SERVER).loginVisitor().compose(RxUtil.<BaseResp<LoginBean>>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void getWxOpenID(String appId, String secret, String code, String grant_type, ServiceCallback callback) {
        RxService.createBasicApi(CommonApi.class, mInstance.WX_SERVER).getWxOpenID(appId, secret, code, grant_type).compose(RxUtil.<WxBean>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void getWxUserInfo(String access_token, String openid, ServiceCallback callback) {
        RxService.createBasicApi(CommonApi.class, mInstance.WX_SERVER).getWxUserInfo(access_token, openid).compose(RxUtil.<WxBean>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void loginWx(Map<String, Object> body, ServiceCallback callback) {
        RxService.createBasicApi(CommonApi.class, mInstance.USER_SERVER).loginWx(body).compose(RxUtil.<BaseResp<LoginBean>>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void logout(ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.USER_SERVER).logout(HttpsUtil.getCommonPostRequest()).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void getSmsCode(Map<String, Object> body, ServiceCallback callback) {
        RxService.createBasicApi(CommonApi.class, mInstance.SMS_SERVER).getSmsCode(body).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void checkSmsCode(Map<String, Object> body, ServiceCallback callback) {
        RxService.createBasicApi(CommonApi.class, mInstance.SMS_SERVER).checkSmsCode(body).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void register(Map<String, Object> body, ServiceCallback callback) {
        RxService.createBasicApi(CommonApi.class, mInstance.USER_SERVER).register(body).compose(RxUtil.<BaseResp<LoginBean>>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void registerWx(Map<String, Object> body, ServiceCallback callback) {
        RxService.createBasicApi(CommonApi.class, mInstance.USER_SERVER).registerWx(body).compose(RxUtil.<BaseResp<LoginBean>>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void clearUser(ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.USER_SERVER).clearUser(HttpsUtil.getCommonPostRequest()).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void checkVersion(ServiceCallback callback) {
        RxService.createBasicApi(CommonApi.class, mInstance.API_SERVER).checkVersion(BuildConfig.VERSION_CODE).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void changePsd(Map<String, Object> body, ServiceCallback callback) {
        RxService.createBasicApi(CommonApi.class, mInstance.USER_SERVER).changePsd(body).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }


    public void getBanner(ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.HOME_SERVER).getBanner().compose(RxUtil.<BaseResp<List<BannerBean>>>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void clickBanner(String id, ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.HOME_SERVER).clickBanner(id).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }


    public void uploadFile(File file, final UploadCallback callback) {
        RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), file);
        FileRequestBody fileRequestBody = new FileRequestBody(requestFile, (currentLength, contentLength) -> {
            //获取上传的比例
            callback.onProgress(currentLength, contentLength);
        });
        MultipartBody.Part requestImgPart = MultipartBody.Part.createFormData("file", file.getName(), fileRequestBody);
        RxService.createApiUploadFor(CommonApi.class, mInstance.COMMON_SERVER).uploadFile(requestImgPart).compose(RxUtil.<BaseResp<UploadBean>>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void uploadFile(Bitmap bitmap, final UploadCallback callback) {
        BitmapRequestBody fileRequestBody = new BitmapRequestBody(bitmap);
        MultipartBody.Part requestImgPart = MultipartBody.Part.createFormData("file", System.currentTimeMillis() + ".png", fileRequestBody);
        RxService.createApiUploadFor(CommonApi.class, mInstance.COMMON_SERVER).uploadFile(requestImgPart).compose(RxUtil.<BaseResp<UploadBean>>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void changePhone(Map<String, Object> body, ServiceCallback callback) {
        RxService.createBasicApi(CommonApi.class, mInstance.USER_SERVER).changePhone(body).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void mainCategory(ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.CATEGORY).category().compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void mainDel(String token, String ids, ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.CATEGORY).del(token, ids).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void mainCollectAlbum(String id, ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.CATEGORY).collectAlbum(id).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void saveAlbum(Map<String, String> map, ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.CATEGORY).saveAlbum(map).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void preDetail(ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.CATEGORY).preDetail().compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void mainCancelCollectAlbum(String id, ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.CATEGORY).cancelCollectAlbum(id).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    /**
     * keyword 	string 	是 	关键字
     * page 	string 	是 	第几页，默认第1页
     * limit 	string 	是 	每页几条，默认10条
     * begin_date 	string 	是 	开始时间，格式2022-01-01
     * end_date
     *
     * @param callback
     */
    public void mainCollectList(String keyword, String page, String begin_date, String end_date, ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.CATEGORY).collectList(keyword, page, "10", begin_date, end_date).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void gallerySysCategory(ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.CATEGORY_SYS).galleryCategory().compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }


    /**
     * category_id 	string 	是 	系统贴图分类ID
     * keyword 	string 	是 	关键字
     * page 	string 	是 	第几页
     * limit 	string 	是 	每页几条
     * sort_field 	string 	否 	排序字段：使用次数use_count、上架时间createtime
     * sort_order 	string 	否 	排序：asc正序、desc倒序
     */
    public void gallerySysList(String category_id, String keyword, String page, String sort_field, String sort_order, ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.CATEGORY_SYS).gallerySysList(category_id, keyword, page, "10", sort_field, sort_order).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void galleryMineList(ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.CATEGORY_SYS).galleryMineList().compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void galleryCollectList(String category_id, String keyword, String sort_field, String sort_order, ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.CATEGORY_SYS).galleryCollectList(category_id, keyword, sort_field, sort_order).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void gallerySysCollect(String id, ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.CATEGORY_SYS).collectMap(id).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void galleryMineDel(String id, ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.CATEGORY_SYS).delMap(id).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void gallerySysCollectCancel(String id, ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.CATEGORY_SYS).cancelCollectMap(id).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }


    /**
     * token 	string 	是 	token
     * page 	string 	是 	第几页
     * limit 	string 	是 	每页几条
     * keyword 	string 	是 	关键字
     * category_id 	string 	是 	分类ID
     * begin_date 	string 	是 	开始时间，格式2022-01-01
     * end_date 	string 	是 	结束时间，格式2022-01-01
     */
    public void listRecycle(String token, String page, String keyword, String category_id, String begin_date, String end_date, ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.CATEGORY).listRecycle(token, page, "10", keyword, category_id, begin_date, end_date).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    /**
     * token 	string 	是 	token
     * ids 	string 	是 	任务ID,多条逗号分隔
     */
    public void delComplete(String token, String ids, ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.CATEGORY).delComplete(token, ids).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    /**
     * token 	string 	是 	token
     * ids 	string 	是 	任务ID,多条逗号分隔
     */
    public void restore(String token, String ids, ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.CATEGORY).restore(token, ids).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    //获取VIP信息
    public void getVipInfo(ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.VIP_INFO).vipInfo().compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    //获取会员资格
    public void getMembershipRules(ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.MEMBERSHIP_RULES).MembershipRules().compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    //获取会员卡列表
    public void getVipCard(ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.VIP_CARD).VipCard().compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void getHistory(String page, String limit, ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.HISTORY).History(page, limit).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    //新建背景分类
    public void getSelectBackClass(ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.BACK_CATEGORY).SelectBackClass().compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    //新建背景列表
    public void getSelectBackList(String category_id, String page, String limit, ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.BACK_LIST).SelectBackList(category_id, page, limit).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void getSelectIntro(String page, String limit, String keyword, ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.INTRO).intro(page, limit, keyword).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void getSelectRemark(String page, String limit, String keyword, ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.REEMARK).remark(page, limit, keyword).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void getCanAddOrder(ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.CAN_ADDORDER).canAddOrder().compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void getClassPhoto(ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.PHOTO_CLASS).Category().compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    //删除简介
    public void getDeleteIntro(String content, ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.DELETE_INTRO).deleteIntro(content).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void getDeleteRemark(String content, ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.DELETE_REMARK).deleteRmark(content).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    //新建任务
    public void postNewSave(String token, String id, String category_id, String background_id, String background_image, String map_id, String map_image, String images, String choose_images, String choose_image, String intro, String cover_image, String remark, ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.POST_SAVE).PostSave(token, id, category_id, background_id, background_image, map_id, map_image, images, choose_images, choose_image, intro, cover_image, remark).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void getUploadFile(String token, File file, final UploadCallback callback) {
        RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), file);
        FileRequestBody fileRequestBody = new FileRequestBody(requestFile, (currentLength, contentLength) -> {
            //获取上传的比例
            callback.onProgress(currentLength, contentLength);
        });
        MultipartBody.Part requestImgPart = MultipartBody.Part.createFormData("file", file.getName(), fileRequestBody);
        RxService.createApiUploadFor(CommonApi.class, mInstance.UPLOAD_FILE).UploadFile(token, requestImgPart).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void getList(String token, String page, String limit, String keyword, String category_id, String start, String end, ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.CATEGORY).list(token, page, limit, keyword, category_id, start, end).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void detail(int id, ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.CATEGORY).detail(id).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void orderPay(Map<String, Object> body, ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.VIP_PAY).orderPay(body).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void addFeedback(String image, String desc, ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.API_SERVER).addFeedback(image, desc).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void uploadPath(String path, final UploadCallback callback) {
        Bitmap bitmap = BitmapManager.getInstance().get(path);
        uploadBitmap(bitmap, callback);
    }

    public void uploadBitmap(Bitmap bitmap, final UploadCallback callback) {
        BitmapRequestBody fileRequestBody = new BitmapRequestBody(bitmap);
        MultipartBody.Part requestImgPart = MultipartBody.Part.createFormData("file", System.currentTimeMillis() + ".png", fileRequestBody);
        RxService.createApiUploadFor(CommonApi.class, mInstance.COMMON_SERVER).uploadFile(requestImgPart).compose(RxUtil.<BaseResp<UploadBean>>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));

    }

    public void addMap(String image, ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.API_SERVER).addMap(image).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

    public void getAddUseCount(String map_id, ServiceCallback callback) {
        RxService.createApiFor(CommonApi.class, mInstance.ADD_USECOUNT).addUseCount(map_id).compose(RxUtil.<BaseResp>handleRestfullResult()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(responseBean -> {
            callback.onSuccess(responseBean);
        }, throwable -> mInstance.handlerThrowable(throwable, callback));
    }

}
